package com.example.student.Controller;

import com.example.student.Service.GradeService;
import com.example.student.entity.ApiResponse;
import com.example.student.entity.Grade;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/grades")
public class GradeController {

    @Autowired
    private GradeService gradeService;

    @GetMapping("stAll")
    public ApiResponse listAllGrades() {
        List<Grade> grades = gradeService.listAll();
        return new ApiResponse(200, "获取所有成绩成功", grades);
    }

    @GetMapping("/getByCourseId/{courseId}")
    public ApiResponse getGradesByCourseId(@PathVariable Long courseId) {
        List<Grade> grades = gradeService.getByCourseId(courseId);
        return new ApiResponse(200, "获取课程成绩成功", grades);
    }

    @PostMapping("/update")
    public ApiResponse updateGrade(@RequestBody Grade grade) {
        gradeService.update(grade);
        return new ApiResponse(200, "更新成绩成功", null);
    }

    @GetMapping("/getByRange/{minScore}/{maxScore}")
    public ApiResponse getGradesByRange(@PathVariable Double minScore, @PathVariable Double maxScore) {
        List<Grade> grades = gradeService.getByRange(minScore, maxScore);
        return new ApiResponse(200, "获取指定成绩范围内的成绩成功", grades);
    }
}